// 生成器

function * foo () {
    console.log("3123")
    return 100
}
const res = foo()
console.log(res.next())

function * foo () {
    console.log("1111")
    yield 100
    console.log("2222")
    yield 200
    console.log("3333")
    yield 300
}
const gen = foo()
console.log(gen.next())
console.log(gen.next())
console.log(gen.next())

// 应用
function * createIdMaker() {
    let id = 1
    while(true) {
        yield id++
    }
}

const idMaker =  createIdMaker()
console.log(idMaker.next())
console.log(idMaker.next())
console.log(idMaker.next())

// 
const todos = {
    life: ["吃饭", "睡觉", "打游戏"],
    learn: ["语文", "历史", "数学"],
    work: ["喝茶"],
    [Symbol.iterator]:function * () {
        const all = [...this.life, ...this.learn, ...this.work]
        for (const iterator of all) {
            yield iterator
        }
    }
}
for (const item of todos) {
    console.log(item)
}